/******************************************************************************* * main.cppC
 *
 * Copyright (c) 2012, Varuna L Amachi. All rights reserved.
 *
 * This program/library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This program/library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301  USA
 ******************************************************************************/

#include <QtGui/QApplication>
#include <QObject>
#include <ui/TanyatuUiGlobal.h>
#include <core/manager/T.h>
#include <core/engine/PhononAudioEngine.h>
#include <core/stdcomps/StandardAudioLibrary.h>
#include <core/stdcomps/StandardAudioManager.h>
#include <core/stdcomps/StandardHistoryManager.h>
#include <core/stdcomps/StandardPlaylist.h>
#include <core/stdcomps/StandardPlaylistManager.h>
#include <core/datasource/StandardDataRetriever.h>
#include <core/datasource/StandardDataSourceManager.h>
#include <core/datasource/StandardDataUpdater.h>
#include <core/utils/FileSystemUtil.h>

#include "ChilliWindow.h"
#include "ComponentManager.h"
#include "audiolib/AudioLibView.h"
#include "audiobrowser/AudioBrowserView.h"
#include "common/ChilliCache.h"


void initCoreComponents( QObject *parent )
{
    Tanyatu::FileSystemUtil::initTanyatuFS();

    Tanyatu::Engine::AbstractEngine *engine =
            new Tanyatu::Engine::PhononAudioEngine( parent );
    Tanyatu::Component::AbstractAudioLibrary *audLib =
            new Tanyatu::Component::StandardAudioLibrary( parent );
    Tanyatu::Component::AbstractAudioManager *audMan =
            new Tanyatu::Component::StandardAudioManager( parent );
    Tanyatu::Component::AbstractPlaylist *playlist =
            new Tanyatu::Component::StandardPlaylist( parent );
    Tanyatu::Component::AbstractPlaylistManager *plMan =
            new Tanyatu::Component::StandardPlaylistManager( parent );
    Tanyatu::Component::AbstractHistoryManager *hisMan =
            new Tanyatu::Component::StandardHistoryManager( parent );
    Tanyatu::DataSource::IDataSourceManager *dsMan =
            new Tanyatu::DataSource::StandardDataSourceManager();
    Tanyatu::DataSource::IDataRetriever *dataRetriever =
            new Tanyatu::DataSource::StandardDataRetriever();
    Tanyatu::DataSource::IDataUpdater *dataUpdater =
            new Tanyatu::DataSource::StandardDataUpdater();

    Tanyatu::T::init( engine,
                      audLib,
                      audMan,
                      playlist,
                      plMan,
                      hisMan,
                      dsMan,
                      dataRetriever,
                      dataUpdater,
                      Tanyatu::T::Logger::Log_Error );

    QHash< QString, QString > params;
    params.insert( "dbname",
                   Tanyatu::FileSystemUtil::getPathFromTanyatuDir(
                       "tanyatu.sqlite" ));
    dsMan->init( params );
    audLib->init();
    audMan->init();
    plMan->init();
    hisMan->init();
}

void initUiComponents( QMainWindow *win )
{
    GreenChilli::ComponentManager::get()->addComponent(
                new GreenChilli::AudioLib::AudioLibView( win ));
    GreenChilli::ComponentManager::get()->addComponent(
                new GreenChilli::AudioBrowser::AudioBrowserView( win ));
//    GreenChilli::ComponentManager::get()->addComponent(
//                new );
}


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    CHILLI_CACHE()->insertPixmap( "star_empty", ":/images/nothot" );
    CHILLI_CACHE()->insertPixmap(  "star_filled", ":/images/hot" );
    QCoreApplication::instance()->setApplicationName( "GreenChilli" );
    a.setApplicationName( QObject::tr( "GreenChilli" ));
    initCoreComponents( 0 );
    GreenChilli::ChilliWindow win;
    win.setWindowTitle( "GreenChilli" );
    win.setWindowIcon( QIcon( ":/images/greenchilli" ));
    initUiComponents( &win );
    win.show();
    return a.exec();
}

